Pre-requisites:

The following chunk sets up rules for all the chunks in the document. I set the knits options for the chunks so that by default messages generated by R are not displayed.

Please notice the alternative way to name the chunk (within the curly brackets, and not after the #| as we’ve seen before). Similarly, other YAML options that we have seen listed after #| could be just used within the curly brackets. For example `{r chunk_name, include=FALSE}.

Click here to show the code
knitr::opts_chunk$set(message = FALSE)

In this second package I load all the necessary packages. I also use herefor file referencing and automatic working directory setting.

Click here to show the code
pacman::p_load(here, tidyverse, ggimage, palmerpenguins, dplyr, ggpattern, patchwork, png, rasterImage, grid)
here::i_am("images_in_R_plots.qmd")

Add an image in R plot

Here I want to show you how to add images to your plot. There are different ways to do this, depedning on what you would like to achieve.

Choose a tab for different ways to add the logo image to ggplots: